/*
 * Copyright (c) 2022 Kirky
 * Licensed under the Open Software Licence, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/osl-3.0.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lingeringdream.luciole.model.helper;

import com.lingeringdream.luciole.model.entity.Classification;
import com.lingeringdream.luciole.model.entity.Privates;
import com.lingeringdream.luciole.model.entity.User;
import ohos.data.resultset.ResultSet;

/**
 * ResultSet转实体类
 *
 * @author Kirky
 * @version 1.0
 * @date 2022/5/3
 */
public class ResultSetHelper {
    public static Classification resultSet2Classification(ResultSet resultSet) {
        Classification classification = new Classification();
        classification.setId(resultSet.getInt(resultSet.getColumnIndexForName("cid")));
        classification.setcName(resultSet.getString(resultSet.getColumnIndexForName("cname")));
        classification.seteName(resultSet.getString(resultSet.getColumnIndexForName("ename")));
        classification.setClazz(resultSet.getInt(resultSet.getColumnIndexForName("class")));
        classification.setHarmful(resultSet.getString(resultSet.getColumnIndexForName("harmful")));
        classification.setSuggestion(resultSet.getString(resultSet.getColumnIndexForName("suggestion")));
        classification.setUpdate(resultSet.getLong(resultSet.getColumnIndexForName("update")));
        return classification;
    }

    public static User resultSet2User(ResultSet resultSet) {
        User user = new User();
        user.setUid(resultSet.getLong(resultSet.getColumnIndexForName("uid")));
        user.setHuaweiId(resultSet.getString(resultSet.getColumnIndexForName("union_id")));
        user.setTel(resultSet.getString(resultSet.getColumnIndexForName("tel")));
        user.setUname(resultSet.getString(resultSet.getColumnIndexForName("uname")));
        user.setGender(resultSet.getInt(resultSet.getColumnIndexForName("gender")) == 1);
        user.setPassword(resultSet.getString(resultSet.getColumnIndexForName("password")));
        user.setRegistration(resultSet.getLong(resultSet.getColumnIndexForName("registration")));
        user.setBirth(resultSet.getLong(resultSet.getColumnIndexForName("birth")));
        user.setBrief(resultSet.getString(resultSet.getColumnIndexForName("brief")));
        user.setPkey(resultSet.getString(resultSet.getColumnIndexForName("pkey")));
        user.setAvatars(resultSet.getString(resultSet.getColumnIndexForName("avatars")));
        user.setUpdate(resultSet.getLong(resultSet.getColumnIndexForName("update")));
        return user;
    }

    public static Privates resultSet2Private(ResultSet resultSet) {
        Privates privates = new Privates();
        privates.setName(resultSet.getString(resultSet.getColumnIndexForName("name")));
        privates.setPurpose(resultSet.getString(resultSet.getColumnIndexForName("purpose")));
        privates.setType(resultSet.getInt(resultSet.getColumnIndexForName("type")));
        privates.setLast(resultSet.getLong(resultSet.getColumnIndexForName("last")));
        privates.setCount(resultSet.getInt(resultSet.getColumnIndexForName("count")));
        return privates;
    }
}
